/**
 * @author: 善良的YWJ
 * @Created by shanliangdeYWJ on 2020/09/29 16:30:59
 * @file: api.js
 * @description:
 * ==================
 * 接口
 * ==================
 * @link [Github](https://github.com/shanliangdeYWJ)
 */

const express = require('express');
const router = express.Router();
const { toLowerLine } = require('../utils');

const {
  gftopenIndexLunbo, // /gftopen/index/lunbo
  gftopenAboutLunbo, // /gftopen/about/lunbo
  gftopenAboutIntroduce, // /gftopen/about/introduce
  gftopenProductLunbo, // /gftopen/product/lunbo
  gftopenProductCagegrate, // /gftopen/product/cagegrate
  gftopenProductPipeline, // /gftopen/product/pipline
  gftopenProductPlumbing, // /gftopen/product/plumbing
  gftopenProductBuilding, // /gftopen/product/building
  gftopenServiceLunbo, // /gftopen/service/lunbo
  gftopenServiceBrochures, // /gftopen/service/brochures
  gftopenNewsLunbo, // /gftopen/news/lunbo
  gftopenJoinLunbo // /gftopen/join/lunbo
} = require('../api/api');

//#region 自动接口生成
const apiObj = require('../api/api');
const apiNameArr = [];

const ApiList = [];
// 生成 接口列表数组 
// 1. 用于 api 页面展示接口
// 2.用于 循环生成接口
for (const name in apiObj) {
  const apiName = '/' + toLowerLine(name, '/');
  apiNameArr.push({ apiName, data: apiObj[name] });

  ApiList.push(`<li>${apiName}</li>`);
}

/* Api 界面 */
router.get('/gftopen/api', function (req, res) {
  res.end(`<h1>Welcome To Api Page</h1>${ApiList}`);
});

// for (let i = 0; i < apiNameArr.length; i++) {
//   router.get(apiNameArr[i].apiName, function (req, res) {
//     res.send({
//       message: apiNameArr[i].data,
//       meta: { msg: 'success', status: 200 }
//     });
//   });
// }
//#endregion 自动接口生成结束

//#region 首页接口
router.get('/gftopen/index/lunbo', function (req, res) {
  res.send({
    message: gftopenIndexLunbo,
    meta: { msg: 'success', status: 200 }
  });
});
//#endregion

//#region 关于我们页面接口
router.get('/gftopen/about/lunbo', function (req, res) {
  res.send({
    message: gftopenAboutLunbo,
    meta: { msg: 'success', status: 200 }
  });
});
router.get('/gftopen/about/introduce', function (req, res) {
  res.send({
    message: gftopenAboutIntroduce,
    meta: { msg: 'success', status: 200 }
  });
});
//#endregion

//#region 产品页面接口
router.get('/gftopen/product/lunbo', function (req, res) {
  res.send({
    message: gftopenProductLunbo,
    meta: { msg: 'success', status: 200 }
  });
});
router.get('/gftopen/product/cagegrate', function (req, res) {
  res.send({
    message: gftopenProductCagegrate,
    meta: { msg: 'success', status: 200 }
  });
});
router.get('/gftopen/product/pipeline', function (req, res) {
  res.send({
    message: gftopenProductPipeline,
    meta: { msg: 'success', status: 200 }
  });
});
router.get('/gftopen/product/plumbing', function (req, res) {
  res.send({
    message: gftopenProductPlumbing,
    meta: { msg: 'success', status: 200 }
  });
});
router.get('/gftopen/product/building', function (req, res) {
  res.send({
    message: gftopenProductBuilding,
    meta: { msg: 'success', status: 200 }
  });
});
//#endregion

//#region 服务页面接口
router.get('/gftopen/service/lunbo', function (req, res) {
  res.send({
    message: gftopenServiceLunbo,
    meta: { msg: 'success', status: 200 }
  });
});

router.get('/gftopen/service/brochures', function (req, res) {
  var result = gftopenServiceBrochures.brochures.filter(item => item.name.search(req.query.type) !== -1);
  res.send({
    message: { brochures: result },
    meta: { msg: 'success', status: 200 }
  });
});
//#endregion

//#region 新闻页面接口
router.get('/gftopen/news/lunbo', function (req, res) {
  res.send({
    message: gftopenNewsLunbo,
    meta: { msg: 'success', status: 200 }
  });
});

//#endregion

//#region 加入我们页面接口
router.get('/gftopen/join/lunbo', function (req, res) {
  res.send({
    message: gftopenJoinLunbo,
    meta: { msg: 'success', status: 200 }
  });
});

//#endregion
module.exports = router;
